<?php
namespace app\setting\controller;
use think\Request;
use app\common\controller\AdminBase;

class ApiAdminIp extends AdminBase
{
    public function itemAdd()
    {
        $ip = input('post.ip');
        $info = input('post.info');
        db('BaseIp')->insert(array(
            'ip' => $ip,
            'info' => $info,
        ));
        return jsonSuccess('成功');
    }
    
    public function itemEdit()
    {
        $id = input('post.id');
        $ip = input('post.ip');
        $info = input('post.info');
        $itemInfo = db('BaseIp')->where('id',$id)->find();
        if (!$itemInfo) {
          return jsonError('修改项不存在');
        }
        db('BaseIp')->where('id',$id)->update(array(
            'ip' => $ip,
            'info' => $info,
        ));
        return jsonSuccess('成功');
    }
    
    public function itemDel()
    {
        $id = input('post.id');
        if (!$id) {
          return jsonError('缺少参数');
        }
        $itemInfo = db('BaseIp')->where('id',$id)->find();
        if (!$itemInfo) {
          return jsonError('删除项不存在');
        }
        db('BaseIp')->where('id',$id)->delete();
        return jsonSuccess('成功');
    }
    
    public function itemSelect()
    {
        $status = input('post.status');
        $orderBy = input('post.orderBy');
        $order = input('post.order');
        $page = input('post.page');
        $limit = input('post.limit');
        $limit ? $limit : 10;
        $orderBy = $orderBy ? $orderBy : 'id';
        $order = $order ? $order : 'desc';
        
        $itemList = db('BaseIp')->page($page,$limit)->order($orderBy,$order)->select();
        $total = db('BaseIp')->count();
        return jsonSuccess('',['itemList' => $itemList,'total' => $total]);
    }
 
}